import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: '工作台',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '工作台', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/transit',
    component: Layout,
    meta: {
      title: '基础数据管理',
      icon: 'el-icon-medal',
      breadcrumb: true
    },
    hidden: false,
    alwaysShow: true,
    children: [
      {
        path: '/branches/organization-manage',
        component: () => import('@/views/branches/organization-manage/index'),
        meta: {
          title: '机构管理',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/branches/institutions-jobs-area',
        component: () =>
          import('@/views/branches/institutions-jobs-area/index'),
        meta: {
          title: '机构作业范围',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/transit/freight-manage',
        component: () => import('@/views/transit/freight-manage/index'),
        meta: {
          title: '运费管理',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      }
    ]
  },

  {
    path: '/transit1',
    component: Layout,
    meta: {
      title: '车辆管理',
      icon: 'el-icon-aim',
      breadcrumb: true
    },
    hidden: false,
    alwaysShow: true,
    children: [
      {
        path: '/transit/car-models',
        component: () => import('@/views/transit/car-models/index'),
        meta: {
          title: '车型管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/transit/vehicle',
        component: () => import('@/views/transit/vehicle/index'),
        meta: {
          title: '车辆列表',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/transit/vehicle-detail/:id',
        component: () => import('@/views/transit/vehicle/vehicle-detail'),
        meta: {
          title: '车辆详情',
          icon: '',
          breadcrumb: true
        },
        hidden: true
      },
      {
        path: '/transit/car-register',
        component: () => import('@/views/transit/car-register/index'),
        meta: {
          title: '回车登记',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      }
    ]
  },
  {
    path: '/transit2',
    component: Layout,
    meta: {
      title: '员工管理',
      icon: 'el-icon-user',
      breadcrumb: true
    },
    hidden: false,
    alwaysShow: true,
    children: [
      {
        path: '/branches/operational-range',
        name: 'operational-range',
        component: () => import('@/views/branches/operational-range/index'),
        meta: {
          title: '快递员管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/branches/operational-range/jobArea', // 作业范围分配
        component: () =>
          import('@/views/branches/operational-range/jobArea.vue'),
        meta: {
          title: '作业范围分配' // 显示在导航的文本
        },
        hidden: true
      },
      {
        path: '/transit/driver',
        component: () => import('@/views/transit/driver/index'),
        meta: {
          title: '司机管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      // 司机详情
      {
        path: '/dirverList',
        component: () => import('@/views/transit/driver/dirverList.vue'),
        name: 'dirverList',
        hidden: true,
        meta: { title: '司机详情', noCache: true, pageHeader: true }
      },

      {
        path: '/transit/workArrange-manage',
        component: () => import('@/views/transit/workArrange-manage/index'),
        meta: {
          title: '排班管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/transit/workArrange-manage/scheduling',
        component: () => import ('@/views/transit/workArrange-manage/scheduling.vue'),
        hidden: true,
        meta: {
          title: '排班设置'
        }
      }
    ]
  },
  {
    path: '/business',
    component: Layout,
    meta: {
      title: '业务管理',
      icon: 'el-icon-set-up',
      breadcrumb: true
    },
    hidden: false,
    alwaysShow: true,
    children: [
      {
        path: '/business/order-manage',
        component: () => import('@/views/business/order-manage/index'),
        meta: {
          title: '订单管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/business/waybill',
        component: () => import('@/views/business/waybill/index'),
        meta: {
          title: '运单管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/business/order-s/:id?',
        component: () => import('@/views/business/order-s/index'),
        meta: {
          title: '订单详情'
        },
        hidden: true,
        alwaysShow: false
      }
    ]
  },
  {
    path: '/transport',
    component: Layout,

    meta: {
      title: '调度管理',
      icon: 'el-icon-service',
      breadcrumb: true
    },
    hidden: false,
    alwaysShow: true,
    children: [
      {
        path: '/transport/transport-task',
        component: () => import('@/views/transport/transport-task/index'),

        meta: {
          title: '运输任务管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/transport/line-manage',
        component: () => import('@/views/transport/line-manage/index'),

        meta: {
          title: '线路管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/branches/pickUptask',
        component: () => import('@/views/branches/pickUptask/index'),

        meta: {
          title: '取件作业管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      },
      {
        path: '/branches/dispatchTask',
        component: () => import('@/views/branches/dispatchTask/index'),

        meta: {
          title: '派件作业管理',
          icon: '',
          breadcrumb: true
        },
        hidden: false,
        alwaysShow: false
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
